<?php
// +----------------------------------------------------------------------
// | JavaJY Framework
// +----------------------------------------------------------------------
// | Copyright (c) http://www.javajy.com
// +----------------------------------------------------------------------
// | Author www.javajy.com <QQ:262042083>
// +----------------------------------------------------------------------
namespace Admin\Controller;


class MasterController extends BaseController{
    function index(){
		$db = M('master');
		$this->user = $db->select();
        $this->display();
    }
	
	function edit(){
		$id = I('id');
		$db = M('master');
		$this->content = $db->where(array('id'=>$id))->find();
		$this->display();
	}
	function addok(){
		if(IS_POST){
			$db = M('master');
			$db->create();
			$re = $db->add();
			if($re){
				$this->redirect('edit','f=addok&id='.$re);
			}else{
				$this->redirect('index','f=adderror');
			}
		}
	}
	function editok(){
		if(IS_POST && I('user')){
			if(!I('pwd')){
				unset($_POST['pwd']);
			}
			$db = M('master');
			$db->create();
			$re = $db->save();
			if($re){
				$this->success('修改成功','index');
			}else{
				$this->error('修改失败');
			}
		}
	}
	function delete(){
		$id = I('id');
		if($id){
			$db = M('master');
			$re = $db->where(array('id'=>$id))->delete();
			if($re){
				$this->success('删除成功',U('index'));
			}else{
				$this->error('删除失败');
			}
		}
	}
	function person(){
		$this->assign('cname','Index');
		$this->assign('aname','Master-person');
		
		$db = M('master');
		$this->content = $db->where(array('user'=>session('AdminUser')))->find();
		$this->display();
    }
	
}